package cn.sycoder.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.PostConstruct;

@Component
//@ConfigurationProperties(prefix = "file-sercice")
public class FileServiceConfig {

    @Autowired
    ApplicationContext context;

//    @Value("${file-server.profile}")
    private static String profile;


    @PostConstruct
    public void init(){ // 初始化获取路径
        String profile = context.getEnvironment().getProperty("file-server.profile");
        FileServiceConfig.profile = profile;
    }

    public static String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        FileServiceConfig.profile = profile;
    }

    // 获取上传头像路径
    public static String getAvatarPath() {
        return profile + "avatar/";
    }

    // 获取下载路径
    public static String getDownloadPath() {
        return profile + "download/";
    }

    // 获取上传路径
    public static String getUploadPath() {
        return profile + "upload/";
    }

}
